package com.borball.store.ui.print;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;

public class PrintTest {

	public static void main(String[] args) {
		FileInputStream psStream = null;
		try {
			psStream = new FileInputStream("G:\\resources\\skin\\Love\\blur.png");
		} catch (FileNotFoundException ffne) {
		}
		if (psStream == null) {
			return;
		}

		DocFlavor psInFormat = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8;

		Doc myDoc = new SimpleDoc(psStream, psInFormat, null);

		PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
		aset.add(new Copies(1));
//		aset.add(MediaSize.);
//		aset.add(Sides.);

		PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, aset);

		if (services.length > 0) {
			DocPrintJob job = services[0].createPrintJob();
			try {
				job.print(myDoc, aset);
			} catch (PrintException pe) {
			}
		}
	}

}
